package demo01;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.stream.Stream;

/*
 *  获取Stream流的两种方式：
 *  Collection类的方法： 
 *      Stream<E> stream()：将Collection单列数组转换为Stream流对象
 *  Stream类的方法：
 *      public static<T> Stream<T> of(T... values)：将若干元素或元素数组转换为Stream流对象
 */
public class Demo03GetStream {
    public static void main(String[] args) {
        // 将单列集合转换为Stream流
        Stream stream1 = new ArrayList<>().stream(); // List -> Stream
        Stream stream2 = new HashSet<>().stream(); // Set -> Straem

        // 将双列集合间接转换为Stream流
        Map<String, String> map = new HashMap<>();
        Stream stream3 = map.keySet().stream(); // Map的键集合 -> Stream
        Stream stream4 = map.values().stream(); // Map的值集合 -> Stream
        Stream stream5 = map.entrySet().stream(); // Map的键值对集合 -> Stream

        // 将数组转换为Stream流
        Stream stream6 = Stream.of(1, 2, 3, 4, 5); // 整型数组 -> Stream
        String[] strings = { "土土", "你是", "粑粑麻麻", "心爱的小孩" };
        Stream stream7 = Stream.of(strings); // 字符串数组 -> Stream
    }
}
